﻿Param(
	[string]$query	
)
Set-ExecutionPolicy Unrestricted
$OutputEncoding = New-Object -typename System.Text.UTF8Encoding


Function Search($query)
{
	$url = 'http://api.zhuishushenqi.com/book/fuzzy-search?query='+$query+'&start=0&limit=20'

	$result = Invoke-WebRequest $url -UserAgent ([Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer)	
	$json = $result.Content|ConvertFrom-Json | Select-Object -Property *
	$books = @()
	foreach($book in $json.books)
	{
		$books += @{Title=$book.title;Author=$book.author;Cover=$book.cover;WordCount=$book.wordCount;Summary=$book.shortIntro;Subject=$book.cat;LastChapter=$book.lastChapter;Id=$book._id;SourceSite=$book.site}
	}
	@{StatusCode=$result.StatusCode;ApiResult=$json.ok;Books=$books} | ConvertTo-Json
}
Search($query)